package com.ruoyi.web.controller.fuwu;

import java.util.List;

import com.ruoyi.system.service.IDrivingcartimeService;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.system.domain.Drivingcartime;
import com.ruoyi.framework.web.base.BaseController;
import com.ruoyi.common.page.TableDataInfo;
import com.ruoyi.common.base.AjaxResult;
import com.ruoyi.common.utils.poi.ExcelUtil;

/**
 * 代驾服务时段 信息操作处理
 * 
 * @author ruoyi
 * @date 2019-07-16
 */
@Controller
@RequestMapping("/system/drivingcartime")
public class DrivingcartimeController extends BaseController
{
    private String prefix = "system/drivingcartime";
	
	@Autowired
	private IDrivingcartimeService drivingcartimeService;
	
	@RequiresPermissions("system:drivingcartime:view")
	@GetMapping()
	public String drivingcartime()
	{
	    return prefix + "/drivingcartime";
	}
	
	/**
	 * 查询代驾服务时段列表
	 */
	@RequiresPermissions("system:drivingcartime:list")
	@PostMapping("/list")
	@ResponseBody
	public TableDataInfo list(Drivingcartime drivingcartime)
	{
		startPage();
        List<Drivingcartime> list = drivingcartimeService.selectDrivingcartimeList(drivingcartime);
		return getDataTable(list);
	}
	
	
	/**
	 * 导出代驾服务时段列表
	 */
	@RequiresPermissions("system:drivingcartime:export")
    @PostMapping("/export")
    @ResponseBody
    public AjaxResult export(Drivingcartime drivingcartime)
    {
    	List<Drivingcartime> list = drivingcartimeService.selectDrivingcartimeList(drivingcartime);
        ExcelUtil<Drivingcartime> util = new ExcelUtil<Drivingcartime>(Drivingcartime.class);
        return util.exportExcel(list, "drivingcartime");
    }
	
	/**
	 * 新增代驾服务时段
	 */
	@GetMapping("/add/{drivingCarId}")
	public String add(@PathVariable("drivingCarId") Integer drivingCarId, ModelMap mmap)
	{
		mmap.put("drivingCarId",drivingCarId);
	    return prefix + "/add";
	}
	
	/**
	 * 新增保存代驾服务时段
	 */
	@RequiresPermissions("system:drivingcartime:add")
	@Log(title = "代驾服务时段", businessType = BusinessType.INSERT)
	@PostMapping("/add")
	@ResponseBody
	public AjaxResult addSave(Drivingcartime drivingcartime)
	{		
		return toAjax(drivingcartimeService.insertDrivingcartime(drivingcartime));
	}

	/**
	 * 修改代驾服务时段
	 */
	@GetMapping("/edit/{drivingcartimeId}")
	public String edit(@PathVariable("drivingcartimeId") Integer drivingcartimeId, ModelMap mmap)
	{
		Drivingcartime drivingcartime = drivingcartimeService.selectDrivingcartimeById(drivingcartimeId);
		mmap.put("drivingcartime", drivingcartime);
	    return prefix + "/edit";
	}
	
	/**
	 * 修改保存代驾服务时段
	 */
	@RequiresPermissions("system:drivingcartime:edit")
	@Log(title = "代驾服务时段", businessType = BusinessType.UPDATE)
	@PostMapping("/edit")
	@ResponseBody
	public AjaxResult editSave(Drivingcartime drivingcartime)
	{		
		return toAjax(drivingcartimeService.updateDrivingcartime(drivingcartime));
	}
	
	/**
	 * 删除代驾服务时段
	 */
	@RequiresPermissions("system:drivingcartime:remove")
	@Log(title = "代驾服务时段", businessType = BusinessType.DELETE)
	@PostMapping( "/remove")
	@ResponseBody
	public AjaxResult remove(String ids)
	{		
		return toAjax(drivingcartimeService.deleteDrivingcartimeByIds(ids));
	}
	
}
